import junit.framework.TestCase;
import org.junit.Test;

public class ComplexTestzrw extends TestCase {
    Complex a1 = new Complex(1, 1);
    Complex a2 = new Complex(-1, -1);
    Complex a3 = new Complex(2, 1);
    Complex a4 = new Complex(1, 2);

    @Test
    public void testgetRealPart() throws Exception {
        assertEquals(1.0, Complex.getRealPart(1.0));
        assertEquals(-2.0, Complex.getRealPart(-2.0));
        assertEquals(0.0, Complex.getRealPart(0.0));
    }

    @Test
    public void testgetImagePart() throws Exception {
        assertEquals(-1.0, Complex.getImagePart(-1.0));
        assertEquals(2.0, Complex.getImagePart(2.0));
        assertEquals(0.0, Complex.getImagePart(0.0));
    }

    @Test
    public void testComplexAdd() throws Exception {
        assertEquals("0.0", a1.ComplexAdd(a2).toString());
        assertEquals("3.0+2.0i", a1.ComplexAdd(a3).toString());
        assertEquals("2.0+3.0i", a1.ComplexAdd(a4).toString());
        assertEquals("1.0", a2.ComplexAdd(a3).toString());
    }

    @Test
    public void testComplexSub() throws Exception {
        assertEquals("2.0+2.0i", a1.ComplexSub(a2).toString());
        assertEquals("-1.0", a1.ComplexSub(a3).toString());
        assertEquals("-1.0", a1.ComplexSub(a4).toString());
        assertEquals("-3.0-2.0i", a2.ComplexSub(a3).toString());
    }

    @Test
    public void testComplexMulti() throws Exception {
        assertEquals("1.0+3.0i", a1.ComplexMulti(a3).toString());
        assertEquals("-2.0", a1.ComplexMulti(a2).toString());
        assertEquals("1.0-3.0i", a2.ComplexMulti(a4).toString());
        assertEquals("5.0", a3.ComplexMulti(a4).toString());
    }

    @Test
    public void testComplexComplexDiv() throws Exception {
        assertEquals("-1.0-1.0i", a1.ComplexDiv(a2).toString());
        assertEquals("0.6+0.6i", a1.ComplexDiv(a3).toString());
        assertEquals("1.0+0.8i", a3.ComplexDiv(a4).toString());
        assertEquals("-0.6-0.6i", a2.ComplexDiv(a3).toString());
    }
}
